﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Tao.FreeGlut;

namespace AvantGameMachine.Input.Mouse
{
    class MouseManager
    {
        private bool[] buttonStates = new bool[3];
        int xPos = -1;
        int yPos = -1;

        internal MouseManager()
        {
        }

        internal void RegisterCallbacks()
        {
            // Set window's to Mouse callback
            Glut.glutMouseFunc(new Glut.MouseCallback(processMouseActiveMotion));
            // Set window's to motion callback
            Glut.glutMotionFunc(new Glut.MotionCallback(processMouse));
            // Set window's to mouse motion callback
            Glut.glutMouseWheelFunc(new Glut.MouseWheelCallback(processMouseWheel));
        }

        // Capture the mouse click event 
        internal void processMouseActiveMotion(int button, int state, int x, int y)
        {
            buttonStates[button] = state != Glut.GLUT_UP;
            UpdatePos(x, y);
        }

        // Translate the x,y windows coordinates to OpenGL coordinates
        internal void processMouse(int x, int y)
        {
            UpdatePos(x, y);
        }

        private void UpdatePos(int _x, int _y)
        {
            xPos = _x;                      // Capture the x value
            yPos = _y;                      // Capture the y value
        }

        // Get the mouse wheel direction
        internal void processMouseWheel(int wheel, int direction, int x, int y)
        {
        }

    }
}
